//
//  R3Cell.h
//  TheRicher
//
//  Created by 李晓东 on 2018/2/4.
//  Copyright © 2018年 PeanutXu. All rights reserved.
//

#import "R3Cell.h"
#import <Masonry.h>

@interface R3Cell ()
@property (nonatomic, strong) UILabel *numberLabel;
@property (nonatomic, strong) UILabel *refernumberLabel;
@property (nonatomic, strong) UILabel *specialLabel;
@property (nonatomic, strong) UILabel *previousLabel;

@end
@implementation R3Cell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.numberLabel];
        [self.contentView addSubview:self.specialLabel];
        [self.contentView addSubview:self.previousLabel];
        
        [self gridLayout];
    }
    return self;
    
}

- (void)setValues:(ShuangSeQiu *)shuangSeQiu{
    NSAttributedString *attributeStr = [self patternText:shuangSeQiu.numberAndRefernumber andRange:NSMakeRange(0, shuangSeQiu.numberAndRefernumber.length - 2) andValue:CellRedBallBackgroundColor andAttribute:NSForegroundColorAttributeName andRange:NSMakeRange(shuangSeQiu.numberAndRefernumber.length - 2, 2), CellBlueBallBackgroundColor, NSForegroundColorAttributeName, nil];
    [_numberLabel setAttributedText:attributeStr];
    
    NSAttributedString *killingAttributeStr = [self patternText:shuangSeQiu.killingNumber andRange:NSMakeRange(0, shuangSeQiu.killingNumber.length) andValue:(id)CellRedBallBackgroundColor andAttribute:NSForegroundColorAttributeName andRange:NSMakeRange(0, 0), nil];
    [_specialLabel setAttributedText:killingAttributeStr];
    
    NSAttributedString *deadthAttributeStr = shuangSeQiu.deadthNumber.length > 0 ? [self patternText:shuangSeQiu.deadthNumber andRange:NSMakeRange(0, shuangSeQiu.deadthNumber.length) andValue:(id)CellBlackBallBackgroundColor andAttribute:NSForegroundColorAttributeName andRange:NSMakeRange(0, 0), nil] : [[NSMutableAttributedString alloc]init];
    [_previousLabel setAttributedText:deadthAttributeStr];
    
}

- (UILabel *)numberLabel{
    _numberLabel = [[UILabel alloc]init];
    [_numberLabel setBackgroundColor:CellNumberBackgroundColor];
    _numberLabel.textAlignment = NSTextAlignmentLeft;
    return _numberLabel;
}

- (UILabel *)specialLabel{
    _specialLabel = [[UILabel alloc]init];
    [_specialLabel setBackgroundColor:CellForecastBackgroundColor];
    _specialLabel.textAlignment = NSTextAlignmentCenter;
    return _specialLabel;
}
- (UILabel *)previousLabel{
    _previousLabel = [[UILabel alloc]init];
    [_previousLabel setBackgroundColor:CellResultBackgroundColor];
    [_previousLabel setTextAlignment:NSTextAlignmentCenter];
    return _previousLabel;
}

- (void)gridLayout{
    [_numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_top);
        make.left.mas_equalTo(self.mas_left);
        make.width.mas_equalTo(self.mas_width).multipliedBy(0.58);
        make.height.mas_equalTo(self.mas_height);
    }];
    
    [_specialLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_top);
        make.left.mas_equalTo(_numberLabel.mas_right).mas_offset(8);
        make.width.mas_equalTo(self.mas_width).multipliedBy(0.18);
        make.height.mas_equalTo(self.mas_height);
    }];
    
    [_previousLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_top);
        make.left.mas_equalTo(_specialLabel.mas_right).mas_offset(8);
        make.width.mas_equalTo(self.mas_width).multipliedBy(0.18);
        make.height.mas_equalTo(self.mas_height);
    }];
}

@end


